package com.msl.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.msl.R;
import com.msl.activity.CGCKActivity;
import com.msl.activity.CGSHActivity;
import com.msl.activity.DJTZ2Activity;
import com.msl.activity.DJTZ3Activity;
import com.msl.activity.DJTZcodeActivity;
import com.msl.activity.RelationActivity;
import com.msl.activity.SCRK117Activity;
import com.msl.activity.SCRK130Activity;
import com.msl.activity.SCRKActivity;
import com.msl.activity.THRKActivity;
import com.msl.activity.TraceabilityActivity;
import com.msl.activity.WWFHActivity;
import com.msl.activity.WWSHActivity;
import com.msl.activity.XSCK131Activity;
import com.msl.activity.XSCKActivity;
import com.msl.bean.AbUserBean;
import java.util.ArrayList;
import java.util.List;
import butterknife.Bind;
import butterknife.ButterKnife;

public class MainAdapter extends BaseAdapter {

    private Context mContext;
    LayoutInflater inflater;
    List<AbUserBean.DataBean.ListBean> mlists = new ArrayList<AbUserBean.DataBean.ListBean>();

    public MainAdapter(Context context, List<AbUserBean.DataBean.ListBean> lists) {
        this.mContext = context;
        inflater = LayoutInflater.from(context);
        mlists = lists;
    }

    @Override
    public int getCount() {
        return mlists == null ? 0 : mlists.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {

        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_main, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        Glide.with(mContext).load(mlists.get(position).getIcon()).into(viewHolder.imgShoukuan);
        viewHolder.txtShoukuan.setText(mlists.get(position).getName());

        viewHolder.shoukuan.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                switch (mlists.get(position).getId())
                {
                    case 1:
                        intent.setClass(mContext, CGCKActivity.class);
                        mContext.startActivity(intent);
                        break;
                    case 2:
                        intent.setClass(mContext, CGSHActivity.class);
                        mContext.startActivity(intent);
                        break;
                    case 3:
                        intent.setClass(mContext, SCRK130Activity.class);
                        mContext.startActivity(intent);
                        break;
                    case 4:
                        intent.setClass(mContext, SCRKActivity.class);
                        mContext.startActivity(intent);
                        break;
                    case 5:
                        intent.setClass(mContext, THRKActivity.class);
                        mContext.startActivity(intent);
                        break;
                    case 6:
                        intent.setClass(mContext, WWFHActivity.class);
                        mContext.startActivity(intent);
                        break;
                    case 7:
                        intent.setClass(mContext, WWSHActivity.class);
                        mContext.startActivity(intent);
                        break;
                    case 8:
                        intent.setClass(mContext, XSCK131Activity.class);
                        mContext.startActivity(intent);
                        break;
                    case 9:
                        intent.setClass(mContext, XSCKActivity.class);
                        mContext.startActivity(intent);
                        break;
                    case 10:
                        intent.setClass(mContext, RelationActivity.class);
                        mContext.startActivity(intent);
                        break;
                    case 11:
                        intent.setClass(mContext, TraceabilityActivity.class);
                        mContext.startActivity(intent);
                        break;
                    case 12:
                        intent.setClass(mContext, DJTZ2Activity.class);
                        mContext.startActivity(intent);
                        break;
                    case 13:
                        intent.setClass(mContext, DJTZ3Activity.class);
                        mContext.startActivity(intent);
                        break;
                    case 14:
                        intent.setClass(mContext, DJTZcodeActivity.class);
                        mContext.startActivity(intent);
                        break;
                    case 15:
                        intent.setClass(mContext, SCRK117Activity.class);
                        mContext.startActivity(intent);
                        break;
                    default:
                        break;
                }
            }
        });

        return convertView;
    }

    static class ViewHolder {
        @Bind(R.id.img_shoukuan)
        ImageView imgShoukuan;
        @Bind(R.id.txt_shoukuan)
        TextView txtShoukuan;
        @Bind(R.id.shoukuan)
        LinearLayout shoukuan;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}

